'use strict';

const Service = require('egg').Service;

class FeedbackService extends Service {
  async list(page = 1, pageSize = 10) {
    const { ctx } = this;
    const offset = parseInt((page - 1) * pageSize);
    const list = await ctx.model.Feedback.findAndCountAll({
      orders: [
        [ 'id', 'desc' ],
      ],
      limit: parseInt(pageSize),
      offset,
    });
    return list;
  }

  async create(body) {
    const { ctx } = this;
    const result = await ctx.model.Feedback.create(body);
    return result ? 'success' : 'fail';
  }

  async delete(id) {
    const { ctx } = this;
    const result = await ctx.model.Feedback.destroy({
      where: {
        id,
      },
    });
    return result;
  }
}

module.exports = FeedbackService;
